﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_BKCDT : System.Web.UI.Page
{
    private string num = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        btnOK.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并提交么？" + "')== false) return false;");
    }
    protected void btnPGCX_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("PGCX.aspx?Pinzhong={0}", "棒材"));
        txtPinzhong.Text = Request.QueryString["Pinzhong"];
        txtPinzhong.Attributes["contentEditable"] = "false";
        txtGuige.Text = Request.QueryString["Guige"];
        txtGuige.Attributes["contentEditable"] = "false";
        num = Request.QueryString["Num"];
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        int checkValue = 0;
        BkcdtInfo bc = new BkcdtInfo();
        bc.Num = num;
        bc.Banzu = Session["用户信息.班组"].ToString();
        bc.Tianbao = Session["用户信息.姓名"].ToString();
        bc.Kday = DateTime.Now.ToString();
        string dh = "";
        switch (Session["用户信息.部门"].ToString())
        {
            case "一高线":
                dh = "YG"; break;
            case "二高线":
                dh = "EG"; break;
            case "大棒线":
                dh = "DB"; break;
            case "四轧库":
                dh = "SZ"; break;
            default:
                break;
        }
        bc.Dtnum = dh + bc.Kday;
        checkValue = BLLFactory.CreateBkcdtBLL().Add(bc);
        if (checkValue >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 提交成功！ ');</script> ");
        }
        if (txtKN.Text.ToString() != "")
        {
            decimal kn = Convert.ToDecimal(txtKN.Text.ToString());
            decimal kndc = Convert.ToDecimal(txtKNDC.Text.ToString());
            decimal knfdc = Convert.ToDecimal(txtKNFDC.Text.ToString());
            if (kn != (kndc + knfdc))
                Response.Write(" <script   language=javascript> window.alert( ' 库内、库内定尺、库内非定尺数量不正确！ ');</script> ");
            else
            {
                BLLFactory.CreateBkcdtBLL().UpdateKN(bc.Dtnum, kn);
                BLLFactory.CreateBkcdtBLL().UpdateKNDC(bc.Dtnum, kndc);
                BLLFactory.CreateBkcdtBLL().UpdateKNFDC(bc.Dtnum, knfdc);
            }
        }
        if (txtDK.Text.ToString() != "")
        {
            decimal dk = Convert.ToDecimal(txtDK.Text.ToString());
            decimal dkdc = Convert.ToDecimal(txtDKDC.Text.ToString());
            decimal dkfdc = Convert.ToDecimal(txtDKFDC.Text.ToString());
            if (dk != (dkdc + dkfdc))
                Response.Write(" <script   language=javascript> window.alert( ' 东库、东库定尺、东库非定尺数量不正确！ ');</script> ");
            else
            {
                BLLFactory.CreateBkcdtBLL().UpdateDK(bc.Dtnum, dk);
                BLLFactory.CreateBkcdtBLL().UpdateDKDC(bc.Dtnum, dkdc);
                BLLFactory.CreateBkcdtBLL().UpdateDKFDC(bc.Dtnum, dkfdc);
            }
        }
        Response.Redirect("BKCDTJL.aspx");
    }
    protected void btnRepeat_Click(object sender, EventArgs e)
    {
        txtKN.Text = "";
        txtKNDC.Text = "";
        txtKNFDC.Text = "";
        txtDK.Text = "";
        txtDKDC.Text = "";
        txtDKFDC.Text = "";
    }
}
